Skip to content

Invalid doctest in PyROS - unclear what behavior should be #3508

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
mrmundt opened this issue Mar 7, 2025 · 2 comments
Open

Invalid doctest in PyROS - unclear what behavior should be #3508

mrmundt opened this issue Mar 7, 2025 · 2 comments

Comments

@mrmundt
Copy link
Contributor

mrmundt commented Mar 7, 2025

Summary

During tracking down a totally different problem, I noticed that there is a doctest from uncertainty_sets that is invalid code and doesn't run. We don't fail on warnings, so we hadn't noticed before.

Steps to reproduce the issue

I noticed this in the doctests when I was looking at something else entirely

D:\a\pyomo\pyomo\doc\OnlineDocs\..\..\pyomo\contrib\pyros\uncertainty_sets.py.rst: 
WARNING: ignoring invalid doctest code: 
'>>> conf_ellipsoid = EllipsoidalSet(\n...     center=np.zeros(4),\n...     shape_matrix=np.diag(range(1, 5)),\n...     scale=None,\n...     gaussian_conf_lvl=0.95,\n... )\n>>> conf_ellipsoid.center\narray([0, 0, 0, 0])\n>>> conf_ellipsoid.shape_matrix\narray([[1, 0, 0, 0]],\n       [0, 2, 0, 0]],\n       [0, 0, 3, 0]],\n       [0, 0, 0. 4]])\n>>> conf_ellipsoid.scale\n...9.4877...\n>>> conf_ellipsoid.gaussian_conf_lvl\n0.95'
...

In looking at that code, there is, in fact, a problem. Here is the code now:


    A 4D 95% confidence ellipsoid:

    >>> conf_ellipsoid = EllipsoidalSet(
    ...     center=np.zeros(4),
    ...     shape_matrix=np.diag(range(1, 5)),
    ...     scale=None,
    ...     gaussian_conf_lvl=0.95,
    ... )
    >>> conf_ellipsoid.center
    array([0, 0, 0, 0])
    >>> conf_ellipsoid.shape_matrix
    array([[1, 0, 0, 0]],
           [0, 2, 0, 0]],
           [0, 0, 3, 0]],
           [0, 0, 0. 4]])
    >>> conf_ellipsoid.scale
    ...9.4877...
    >>> conf_ellipsoid.gaussian_conf_lvl
    0.95

I think it should actually be:

    A 4D 95% confidence ellipsoid:

    >>> conf_ellipsoid = EllipsoidalSet(
    ...     center=np.zeros(4),
    ...     shape_matrix=np.diag(range(1, 5)),
    ...     scale=None,
    ...     gaussian_conf_lvl=0.95,
    ... )
    >>> conf_ellipsoid.center
    array([0., 0., 0., 0.])
    >>> conf_ellipsoid.shape_matrix
    array([[1, 0, 0, 0],
           [0, 2, 0, 0],
           [0, 0, 3, 0],
           [0, 0, 0, 4]])
    >>> conf_ellipsoid.scale
    9.4877...
    >>> conf_ellipsoid.gaussian_conf_lvl
    0.95

The thing that is unclear to me, however - this test fails because conf_ellipsoid.scale outputs np.float64(9.4877...). Is it intended that XX.scale can return an np.float object, or is it intended to be cast to a raw Python float? I didn't want to make an assumption, so I hand this off to the PyROS folks to decide what the right behavior is.

Error Message

Document: api/pyomo.contrib.pyros.uncertainty_sets.EllipsoidalSet
-----------------------------------------------------------------
**********************************************************************
File "..\..\pyomo\contrib\pyros\uncertainty_sets.py", line ?, in default
Failed example:
    conf_ellipsoid.scale
Expected:
    9.4877...
Got:
    np.float64(9.487729036781154)
**********************************************************************
1 item had failures:
   1 of  15 in default
15 tests in 1 item.
14 passed and 1 failed.
***Test Failed*** 1 failure.

Information on your system

Pyomo version: 6.9.2.dev0
Python version: Multiple
Operating system: Windows (NOTE: Only seems to happen on Windows)
How Pyomo was installed (PyPI, conda, source): source
Solver (if applicable):

@mrmundt mrmundt added the bug label Mar 7, 2025
@mrmundt
Copy link
Contributor Author

mrmundt commented Mar 7, 2025

@shermanjasonaf
Copy link
Contributor

shermanjasonaf commented Mar 26, 2025

@mrmundt Thanks for pointing this out. I will discuss with the PyROS Dev Team on 2025-03-28.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants